import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Container示例',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: ContainerDemo(),
    );
  }
}

class ContainerDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Container示例')),
      body: SingleChildScrollView(
        child: Column(
          children: [
            // 5.4.1 Container基础
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Text(
                '5.4.1 Container基础',
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              margin: EdgeInsets.all(20.0),
              color: Colors.orange,
              child: Text('Hello World'),
            ),

            // 5.4.2 Container实例
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Text(
                '5.4.2 Container实例',
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              margin: EdgeInsets.all(20.0),
              padding: EdgeInsets.all(20.0),
              decoration: BoxDecoration(
                color: Colors.blue,
                borderRadius: BorderRadius.circular(10.0),
              ),
              child: Text(
                '这是一个带圆角和内边距的Container',
                style: TextStyle(color: Colors.white),
              ),
            ),

            // 5.4.3 Padding和Margin
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Text(
                '5.4.3 Padding和Margin',
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              margin: EdgeInsets.all(30.0),
              padding: EdgeInsets.all(20.0),
              color: Colors.green,
              child: Text(
                '这个Container有30的外边距和20的内边距',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
